package com.ruix.app.model;

import com.ruix.app.RuiApplication;

import org.json.JSONObject;

/**
 * Created by hadexs on 2017/5/8.
 */

public class AppUpgradeInfo {

    private String name;
    private String version;
    private String versionShort;
    private String changelog;
    private String build;
    private String updateUrl;
    private String downLoadUrl;
    private long size;

    public AppUpgradeInfo parse(JSONObject object) {
        if (object != null) {
            setName(object.optString("name", ""));
            setVersion(object.optString("version", ""));
            setVersionShort(object.optString("versionShort", ""));
            setChangelog(object.optString("changelog", ""));
            setBuild(object.optString("build", ""));
            setUpdateUrl(object.optString("update_url", ""));
            setDownLoadUrl(object.optString("direct_install_url", ""));
            JSONObject binary = object.optJSONObject("binary");
            if (binary != null) {
                setSize(binary.optLong("fsize", 0));
            }
        }
        return this;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public String getChangelog() {
        return changelog;
    }

    public void setChangelog(String changelog) {
        this.changelog = changelog;
    }

    public String getBuild() {
        return build;
    }

    public void setBuild(String build) {
        this.build = build;
    }

    public String getUpdateUrl() {
        return updateUrl;
    }

    public void setUpdateUrl(String updateUrl) {
        this.updateUrl = updateUrl;
    }

    public long getSize() {
        return size;
    }

    public void setSize(long size) {
        this.size = size;
    }

    public String getDownLoadUrl() {
        return downLoadUrl;
    }

    public void setDownLoadUrl(String downLoadUrl) {
        this.downLoadUrl = downLoadUrl;
    }

    public String getVersionShort() {
        return versionShort;
    }

    public void setVersionShort(String versionShort) {
        this.versionShort = versionShort;
    }

    public boolean isNeedUpdate(){
        if (version != null ){
          int result =  version.compareTo(RuiApplication.appVersionCode);
            if (result > 0){
                return true;
            }
        }
        return false;
    }
}
